package threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: admin
 * @Description:
 * @Date: 2018/8/5 16:35
 */

public class Cached {
    public static void main(String[] args){
        ExecutorService cachedThreadPool= Executors.newCachedThreadPool();
        for(int i=0; i<10; i++){
            final int index=i;
            try{
                Thread.sleep(index*1000);
            }
            catch (InterruptedException e){
                e.printStackTrace();
            }
            cachedThreadPool.execute(new Runnable() {
                public void run() {
                    System.out.println(Thread.currentThread().getId()+"\t"+ index);
                }
            });
        }
        cachedThreadPool.shutdown();
    }
}
